#include <boost/multi_index_container.hpp>
#include <boost/multi_index/hashed_index.hpp>
#include <boost/multi_index/member.hpp>
#include <iostream>
#include <string>
 
struct Person
{
    std::string m_name;
    int m_age;
 
    Person(const std::string &name, int age) : m_name(name), m_age(age) {}
};
 
typedef boost::multi_index::multi_index_container<
    Person,
    boost::multi_index::indexed_by<
        boost::multi_index::hashed_non_unique<
            boost::multi_index::member<Person, std::string, &Person::m_name>
        >,
        boost::multi_index::hashed_non_unique<
            boost::multi_index::member<Person, int, &Person::m_age>
        >
    >
> Person_multi;
 
//*a functor for modify method
void set_age(Person &p)
{
    p.m_age = 30;
}
 
int main()
{
    Person_multi persons;
 
    persons.insert(Person("Euler",20));
    persons.insert(Person("Gauss",21));
    persons.insert(Person("Poincare",22));
 
    Person_multi::iterator it = persons.find("Poincare");
    persons.modify(it, set_age); //*iterator and functor
 
    const Person_multi::nth_index<1>::type &age_index = persons.get<1>();
    std::cout << age_index.count(30) << std::endl;
}